// pages/my/signin/signin.js
import{store }from '../../../store/store'
import config from '../../../utils/config'
const api_path='/manage/sys-user'
Page({
  storeBindings: {
    store,
    fields: {
      userId:'userId',
      userName:'userName',
      token:'token'
    }
  },
  /**
   * 页面的初始数据
   */
  data: {
    phone:'',
    password:'',
    userId:null,
    userName:'',
    token:''
  },
//检测手机号输入
userPhoneisNull(e){
  console.log(e.detail)
  this.setData({
    phone:e.detail
  })
}, 
userpasswordisNull(e){
  console.log(e.detail)
  this.setData({
    password:e.detail
  })
}, 
async login(e){
  var that=this
  if(this.data.phone.length===0||this.data.phone.length!=11){
    return false;
  }
  if(this.data.phone.length===0){
    return false;
  }
  let results = await wx.p.request({
    method:'get',
    url:config.BaseUrl+api_path+'/wxlogin',
    data:{phone:this.data.phone,password:this.data.password }
  });
  console.log("结果数据为:",results);
   that.setData({
    userId: results.data.data.result.data.userId,
    userName: results.data.data.result.data.userName,
    token: results.data.data.result.token
  })
  console.log('token:',this.data.token)
  console.log(this.data.userId);
  console.log(this.data.token);
  wx.setStorageSync('token', this.data.token)
  wx.setStorageSync('userName', this.data.userName)
  wx.setStorageSync('userId', this.data.userId)
  wx.reLaunch({
    url: '/pages/my/my'
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})